package com.five.mobile.controller;

import com.five.core.result.Result;
import com.five.pojo.vo.MobileProductListVo;
import com.five.service.ProductRpcService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @DubboReference
    private ProductRpcService productRpcService;


    /**
     * 查询最新10个商品
     * @return
     */
    @RequestMapping(value = "/top10", method = RequestMethod.GET)
    public Result top10(){
        List<MobileProductListVo> list = productRpcService.Top10Products();
        return Result.buildSuccess(list);
    }

    /**
     * 根据分类ID查询商品
     * @param categoryId
     * @return
     */
    @RequestMapping(value = "/queryProductByCategoryId/{id}", method = RequestMethod.GET)
    public Result queryProductByCategoryId(@PathVariable("id") Long categoryId){
        List<MobileProductListVo> list = productRpcService.queryProductByCategoryId(categoryId);
        return Result.buildSuccess(list);
    }

    /**
     * 查询一个商品的详情
     * @param id
     * @return
     */
    @RequestMapping(value = "/queryOne/{id}", method = RequestMethod.GET)
    public Result queryOne(@PathVariable("id") Long id){
        MobileProductListVo mobileProductListVo = productRpcService.listProductsById(id);
        return Result.buildSuccess(mobileProductListVo);
    }

    @RequestMapping(value = "/queryProductByProductName/{productName}", method = RequestMethod.GET)
    public Result queryProductByProductName(@PathVariable("productName") String productName){
        List<MobileProductListVo> list = productRpcService.queryProductByProductName(productName);
        return Result.buildSuccess(list);
    }




}
